
<template>
  <div>
    <div>
      <el-form :inline="true" :model="formInline" class="demo-form-inline">
        <el-form-item label="题库子类名称：">
          <el-input v-model="formInline.userDo" placeholder="请输入"></el-input>
        </el-form-item>
        <!-- <el-form-item label="分类层级：">
          <el-select v-model="formInline.region" placeholder="请选择">
            <el-option label="一年级" value="一年级"></el-option>
            <el-option label="二年级" value="二年级"></el-option>
            <el-option label="三年级" value="三年级"></el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="rests">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row>
        <el-button type="primary" @click="sub">新建题库分类</el-button>

        <el-dialog
          title="新增"
          :visible.sync="visible"
          width="30%"
          :before-close="handleClose"
        >
                 
          <div>
            <!--               类型:<el-input ></el-input> -->
            <!-- 你好:<input type="text" /> -->
            <el-form
              :inline="true"
              :model="formInline"
              class="demo-form-inline"
            >
              <el-form-item label="题库名称">
                <el-input
                  v-model="formInline.poolName"
                  placeholder="题库名称"
                  id="n"
                ></el-input>
              </el-form-item>
              <!-- <el-form-item label="创建人员">
                <el-input
                  v-model="formInline.createMan"
                  placeholder="创建人员"
                ></el-input>
              </el-form-item> -->
              <el-form-item label="父库名称">
                <el-input
                disabled
                  v-model="formInline.poolName2"
                  placeholder="父库名称"
                ></el-input>
              </el-form-item>
              
<!--               
              <el-form-item label="父库名称">
                <el-input
                  v-model="formInline.fid"
                  placeholder="父库fid"
                ></el-input>
              </el-form-item> -->
            </el-form>

                       
          </div>
                     
          <span slot="footer" class="dialog-footer">
                         
            <el-button @click="visible = false">取 消</el-button>              
            <el-button :plain="true" type="primary" @click="insert()">确 定</el-button>      
                 
          </span>
                   
        </el-dialog>

        <!-- <el-button type="success">批量删除</el-button> -->
      </el-row>
     
    </div>

    <!-- <MySearch></MySearch> -->
    <el-table
      ref="multipleTable"
      :data="subject"
      tooltip-effect="dark"
      style="width: 100%; text-align: center; margin-top: 10px"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" prop="id" label="序号" width="50">
      </el-table-column>
      <!-- <el-table-column fixed prop="id" label="id" width="70"> </el-table-column> -->
      <el-table-column fixed prop="poolName" label="题库名称" width="150">
      </el-table-column>
      <!-- <el-table-column prop="fid" label="分类层级" width="120">
      </el-table-column> -->
      <el-table-column prop="order" label="排序值" width="120">
      </el-table-column>
      <el-table-column prop="createMan" label="创建人" width="120">
      </el-table-column>
      <el-table-column prop="updateTime" label="最新修改时间" width="165">
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button  type="text" size="small"
            >查看</el-button
          >
          <el-button @click="handleClick(scope.row)" type="text" size="small"
            >编辑</el-button
          >

           <el-dialog
            :append-to-body="true"
          title="编辑"
          :visible.sync="visibles"
          width="30%"
          :before-close="handleClose"
        >
                 
          <div>

            <el-form
              :inline="true"
              :model="formInline"
              class="demo-form-inline"
            >
              <el-form-item label="题库名称">
                <el-input
                  v-model="formInline.poolName"
                  placeholder="题库名称"

                ></el-input>
              </el-form-item>
            </el-form>

                       
          </div>
                     
          <span slot="footer" class="dialog-footer">
                         
            <el-button @click="visibles = false">取 消</el-button>              
            <el-button type="primary" @click="update()">确 定</el-button>      
                 
          </span>
                   
        </el-dialog>






          <el-button slot="reference" type="text" size="small" @click="delete01(scope.row)" >删除</el-button>

          <!-- <el-button type="text" @click="dialogVisible = true">点击打开 Dialog</el-button> -->

<el-dialog
:append-to-body="true"
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
  <span>确认删除?</span>
  <span slot="footer" class="dialog-footer">
    <el-button type="primary" @click="delete02()">确 定</el-button>
  </span>
</el-dialog>

          


 <!-- <el-button :plain="true" @click="open">打开消息提示</el-button> -->
         
        </template>
      </el-table-column>
    </el-table>
    <!-- <MyPage></MyPage> -->

     <div>
          <div class="block">
    <span class="demonstration"></span>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[2, 5, 8, 10]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
      </div>
  </div>
</template>

<script>
import MySearch from "@/views/issue/search.vue";
import MyPage from "@/views/issue/pages.vue";
import { postData } from "@/utils/Util";


export default {
  created() {
    // console.log(this.$route.query.id==undefined)
    // if(this.$route.query.id==undefined){
    //   // this.findallsons();
    // }else{
    console.log(this.$route.query.id);
     console.log(this.$route.query.poolName);
    // this.findall()
     this.cha.id=this.$route.query.id,
    this.findallson();
   
    this.formInline.fid=this.$route.query.id,
    this.formInline.poolName2=this.$route.query.poolName
     
    // }
  // 
    //  this.findallson();

    // this.findallsons();

    // this.formInline.id=this.$route.query.id;
    // console.log(this.$route.query.id);
   
  },
  methods: {
    findallsons(){
      this.$axios(
         "http://localhost:8080/pool/findspools"

      ).then(res=>{
        console.log(res.data.data);
         this.subject=res.data.data
        //  this.total=res.data.data.length

      })
    },
      


    findallson(){
      // console.log(this.formInline.id);
    this.$axios.post(
  "http://localhost:8080/pool/findSonPool/"+this.page+"/"+this.limit ,{
          id:this.cha.id

         
        }
    ).then(res=>{
      // console.log(res.data.data);
      this.subject=res.data.data.list
      console.log(res);
      this.total=res.data.data.total
      
      

})
    },



    update01(){
      this.visibles=true;

    },

    findfdelete(){
      

      this.$axios.post(
          "http://localhost:8080/pool/findFidPool/",{
            fid:this.fids.fid
          }

      ).then(res=>{
        // console.log(res);
        this.subject=res.data.data
        this.total=res.data.data.length





      })
     


    },

    




    delete02() {
      
     console.log(this.formInline.fid);
     this.fids.fid=this.formInline.fid;


      this.$axios.post(
        "http://localhost:8080/pool/delete/"+this.formInline.id,
         
      ).then(res=>{
        if (res.data.code===520) {
          this.$message(res.data.data+",删除失败")

          
        }else if(res.data.code===200){
          this.$message(res.data.data)



        }
        console.log(res.data.code);

     
        // this.$message('删除成功'),

      this.findfdelete(),
        this.dialogVisible = false;

        

      })
    

      this.visibles = false;
    },

    delete01(row) {
      // console.log(666);
      this.formInline.id=row.id,

      this.formInline.fid=row.fid,

      // console.log(row);
      this.dialogVisible = true;
    },

  
    add01(){

       this.$axios.post("http://localhost:8080/pool/insertSpool",this.formInline, {
        // poolName:this.poolName2
      }).then(res=>{


        console.log(res.data);
        if ( res.data.code===200) {
          this.$message('添加成功');
        }else{
          this.$message(res.data.data+',添加失败');
        }   

         this.$axios.post("http://localhost:8080/pool/findFidPool",{

            fid:this.fids.fid
          }
          
          ).then(res=>{
            console.log(res);
            this.subject=res.data.data

          })
          console.log(this.fids.fid);
        // this.findfdelete()
      });
      
      this.visible = false;



    },


    insert() {

      this.$axios.post(
   "http://localhost:8080/pool/findidPool/"+this.formInline.poolName2
      ).then(res=>{
        // console.log(666);
        if (res.data.code===500) {
          this.$message(res.data.data)
        }
        // console.log(res.data.data);
        this.fids.fid=res.data.data,
       this.formInline.fid=res.data.data,
        
          this.add01();
        }
        
        

        
        
      )

      
    },

    sub() {

      this.visible = true;
      console.log(this.formInline.poolName2);






    },

    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
   

    update() {
      console.log(666);
      // console.log(this.fids.fid),
      this.formInline.fid=this.fids.fid,

      // console.log(this.formInline.fid),

      // this.formInline.fid=this.fid.fid
       
      this.$axios.post("http://localhost:8080/pool/update",{
        id:this.formInline.id,
        poolName:this.formInline.poolName,
        
      })
        .then((res) => {
          console.log(this.formInline.fid);
          this.$axios.post("http://localhost:8080/pool/findFidPool",{

            fid:this.fids.fid
          }
          
          ).then(res=>{
            console.log(res);
            this.subject=res.data.data

          })
          // console.log(res.data);
          //  this.findfdelete();
        })
      this.visibles=false;

      // console.log(999);
    },

    handleSelectionChange() {},

    rests(){
      console.log(777);
      this.alls();
      console.log(this.formInline.userDo),
      this.formInline.userDo=''
      // this.findallsons()
      


    },


    alls(){


      this.$axios.post("http://localhost:8080/pool/findByFidAndSunName",{
        fid:this.cha.id

      }).then(res=>{
        console.log(res);
        if (res.data.data==null) {
          this.$message("无数据")
        }else{

          this.subject=res.data.data
          this.total=res.data.data.length
        }

      })

    },

    onSubmit() {
        

      if (this.formInline.userDo=="") {
        this.$message("请输入关键字")
      }else{
          console.log(this.cha.id);
         this.$axios.post("http://localhost:8080/pool/findByFidAndSunName",{
           fid:this.cha.id,
           poolName:this.formInline.userDo
         }).then(res=>{
           if (res.data.code==500) {
             this.$message(res.data.data)
             
           }else{
           console.log(res.data);

             this.subject=res.data.data
            //  this.total=res.data.data.length
             
           }

         })

      }
      // console.log("submit!");
      // this.findall()
    },
    findall() {
      this.$axios
        .post(
          "http://localhost:8080/pool/findAll/" +
            this.page +
            "/" +
            this.limit
          // this.$axios.post("/api/pool/findAll/"+this.pageinfo.page+"/"+this.pageinfo.limit,
        )
        .then((res) => {
          console.log(res.data.data);
          this.total=res.data.data.total
          this.subject = res.data.data.list;
          
        })
        .catch();
    },

    handleClick(row) {

      this.visibles=true,
      console.log(row);
      this.fids.fid=row.fid;
      this.formInline.id=row.id;
      // console.log(this.id),
      this.formInline.poolName=row.poolName;
      // console.log(this.formInline.poolName);
      
    },
    handleSizeChange(val) {
      this.limit=val
        console.log(`每页 ${val} 条`);
        console.log(this.limit);
        // this.findall()
        this.findallson();

      },
      handleCurrentChange(val) {
        this.page=val
        console.log(`当前页: ${val}`);
        console.log(this.page);
        // this.findall()
        this.findallson();
      }
  },
  components: {
    MySearch,
    MyPage,
  },

  data() {
    return {

      centerDialogVisible: false,
     


      dialogVisible:false,
      visible: false,
      visibles: false,

      form: {},

      formInline: {
        id:"",
        user: "",
        region: "",
        poolName: "",
        createMan: "",
        fid: "",
        poolName2:"",
        userDo:""
        
      },

      forms: {
        poolName: "",
      },

      subject: [],

      fids:{
        fid:""
      },

      pageinfo: {
        page: 1,
        limit: 10,
      },

      su:{
        poolName:"",
      },

      cha:{
        id:""
      },
    
     currentPage4: 1,
     total:100,
     limit:10,
     page:1


     


    };
  },
};
</script>